home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Sound / Subspace68k / src / Subspace68k_HS.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-04  |  54.0 KB  |  1,558 lines

  1. #define P96 //SuRgEoN :for compatibility - still through cgfx
  2.  
  3. #ifdef __PPC__
  4. #define MAXWIDTH  640
  5. #define MAXHEIGHT 480
  6. #else
  7. #define MAXWIDTH  640
  8. #define MAXHEIGHT 480
  9. #endif
  10.  
  11. #define NUMFIELDS 19
  12. #define NUMWAVES 12
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <math.h>
  19.  
  20. #include <exec/types.h>
  21. #include <exec/libraries.h>
  22. #include <exec/memory.h>
  23. #include <exec/devices.h>
  24. #include <graphics/gfx.h>
  25. #include <graphics/gfxbase.h>
  26. #include <intuition/intuition.h>
  27. #include <cybergraphics/cybergraphics.h>
  28.  
  29. #include <proto/exec.h>
  30. #include <proto/dos.h>
  31. #include <proto/intuition.h>
  32. #include <proto/graphics.h>
  33. #include <proto/cybergraphics.h>
  34. #include <proto/icon.h>
  35. #include <proto/keymap.h>
  36. #include <devices/timer.h>
  37. #include <proto/timer.h>
  38.  
  39. #include <workbench/startup.h>
  40. #include <dos/dostags.h>
  41. //#include <graphics/gfxbase.h>
  42. //#include <cybergraphx/cybergraphics.h>
  43. //#include <libraries/picasso96.h>
  44. //#include <clib/picasso96_protos.h>
  45.  
  46. static int BytesPerRow;
  47. static BYTE *GfxAddr;
  48.  
  49. /*
  50. #ifndef __PPC__
  51. extern void ASM TurboUpdate68k(REG(a0,BYTE *), REG(a1,BYTE *),
  52.                                REG(d4,int), REG(d0,int), REG(d1,int),
  53.                                REG(d2,int), REG(d3,int));
  54. #endif
  55. */
  56.  
  57. #ifdef __SASC
  58. struct Library *PPCLibBase;
  59. #include <PowerUP/PPCLib/tasks.h>
  60. ULONG   PPCCallOS(struct Caos*);
  61. ULONG   PPCSetTaskAttrs(void*, struct TagItem*);
  62.  
  63. #define PPCSetTaskAttrs(TaskObject, Tags)       _PPCSetTaskAttrs(PPC_BASE_NAME, TaskObject, Tags)
  64. static __inline ULONG _PPCSetTaskAttrs(void *PPCLibBase, void*TaskObject, struct TagItem*Tags) {
  65.         struct Caos     MyCaos;
  66.         MyCaos.M68kCacheMode    =       IF_CACHEFLUSHALL;
  67.         MyCaos.PPCCacheMode     =       IF_CACHEFLUSHALL;
  68.         MyCaos.a0               =(ULONG) TaskObject;
  69.         MyCaos.a1               =(ULONG) Tags;
  70.         MyCaos.caos_Un.Offset   =       (-192);
  71.         MyCaos.a6               =(ULONG) PPCLibBase;    
  72.         return((ULONG)PPCCallOS(&MyCaos));
  73. }
  74. #endif
  75.  
  76.  
  77. #include "TrackInfo.h"
  78.  
  79. BOOL PluginInit(int argc, char **argv);
  80. void PluginExit(void);
  81. void PluginLoop(void); //mainloop for viasualization effects
  82. void ShowRequester(char *Text, char *Button);
  83. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri);
  84. void MyDeletePort(struct MsgPort *mp);
  85.  
  86. /***************************************************************************/
  87. /* This is the global variables section. Don't change anything here unless */
  88. /* you know what you're doing!                                             */
  89. /***************************************************************************/
  90.  
  91. BYTE             PluginSignal, InfoSignal, ConfigSignal;
  92. ULONG            PluginMask,   InfoMask,   ConfigMask;
  93. BOOL             Accepted;
  94. struct Process   *PluginTask;
  95. struct MsgPort   *PluginMP;
  96. struct MsgPort   *PluginRP;
  97. struct TrackInfo *tinfo;
  98.  
  99. #ifdef __SASC
  100. struct Library     *TimerBase;
  101. #else
  102.  #ifdef __VBCC__ //SuRgEoN
  103. struct Library      *TimerBase = NULL;
  104.  #else
  105. struct Device      *TimerBase;
  106.  #endif
  107. #endif
  108. struct MsgPort     *TimerMP;
  109. struct timerequest *TimerIO = NULL;
  110. struct EClockVal   ev1;
  111. struct EClockVal   ev2;
  112. BYTE               TimerError = -1;
  113. ULONG              EFreq=0;
  114. ULONG              TimerMask;
  115.  
  116. UWORD   TrackInfoPos = 1;
  117.  
  118. UWORD   *PluginRawL;
  119. UWORD   *PluginRawR;
  120. WORD    *PluginSamples;
  121. UWORD   *SpecRawL;
  122. UWORD   *SpecRawR;
  123. WORD *SampleRaw;
  124.  
  125. struct PluginMessage {
  126.         struct Message   msg;
  127.         ULONG            PluginMask;
  128.         struct Process   *PluginTask;
  129.         UWORD            **SpecRawL;
  130.         UWORD            **SpecRawR;
  131.         UWORD            Accepted;
  132.         UWORD            reserved0;
  133.         ULONG            InfoMask;
  134.         struct TrackInfo **tinfo;
  135.         ULONG            ConfigMask;
  136.         WORD             **SampleRaw;
  137. };
  138.  
  139. BOOL OpenTimer(void);
  140. void CloseTimer(void);
  141. void StartTimer(void);
  142.  
  143. /***************************************************************************/
  144. /* This is the main part. Again, don't change anything here if you haven't */
  145. /* got a very good reason to do so!                                        */
  146. /***************************************************************************/
  147.  
  148. int main(int argc, char **argv) {
  149.         struct PluginMessage *PluginMsg;
  150.         struct PluginMessage *ReplyMsg;
  151.  
  152.  
  153.         /* Allocate all user resources */
  154.         if(PluginInit(argc, argv)) {
  155.                 /* Check if a plugin capable instance of AmigaAMP is running */
  156.                 if(PluginMP=FindPort("AmigaAMP plugin port"))   {
  157.                         /* Allocate some sigbits for receiving signals FROM AmigaAMP */
  158.                         PluginSignal = AllocSignal(-1);
  159.                         ConfigSignal = AllocSignal(-1);
  160.                         InfoSignal   = AllocSignal(-1);
  161.                         PluginTask   = (struct Process *)FindTask(NULL);
  162.  
  163.                         if(PluginSignal != -1 && InfoSignal != -1 && PluginSignal != -1) {
  164.                                 PluginMask = 1L << PluginSignal;
  165.                                 ConfigMask = 1L << ConfigSignal;
  166.                                 InfoMask   = 1L << InfoSignal;
  167.  
  168.                                 /* Allocate a message and reply port for sending messages TO AmigaAMP */
  169.                                 #if defined (__SASC) || defined (__VBCC__) //SuRgEoN
  170. #ifdef __PPC__
  171.                                 PluginMsg=PPCAllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  172. #else
  173.                                 PluginMsg=AllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  174. #endif
  175.                                 PluginRP=(struct MsgPort*)MyCreatePort(0,0);
  176.                                 #else
  177.                                 PluginMsg=AllocVecPPC(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR, 0);
  178.  
  179.                                 PluginRP=(struct MsgPort*)CreatePort(0,0);
  180.                                 #endif
  181.  
  182.                                 /* Tell AmigaAMP all the details it needs to know */
  183.                                 PluginMsg->msg.mn_Node.ln_Type = NT_MESSAGE;
  184.                                 PluginMsg->msg.mn_Length       = sizeof(struct PluginMessage);
  185.                                 PluginMsg->msg.mn_ReplyPort    = PluginRP;
  186.                                 PluginMsg->PluginMask          = PluginMask;
  187.                                 PluginMsg->PluginTask          = PluginTask;
  188.                                 PluginMsg->SpecRawL            = &SpecRawL;
  189.                                 PluginMsg->SpecRawR            = &SpecRawR;
  190.                                 PluginMsg->InfoMask            = InfoMask;
  191.                                 PluginMsg->tinfo               = &tinfo;
  192.                                 PluginMsg->ConfigMask          = ConfigMask;
  193.                                 PluginMsg->SampleRaw           = &SampleRaw;
  194.                                 PutMsg(PluginMP, (struct Message *)PluginMsg);
  195.                                 /* Wait for a reply */
  196.                                 WaitPort(PluginRP);
  197.                                 /* Let's see if AmigaAMP accepted our registration attempt */
  198.                                 if(ReplyMsg = (struct PluginMessage *)GetMsg(PluginRP)) Accepted=ReplyMsg->Accepted;
  199.                                 else Accepted=FALSE;
  200.  
  201.                                 if(Accepted) {
  202.                                         /* If it did, start the plugin loop */
  203.                                         //printf("Init ok! - entering plugin loop\n");
  204.                                         PluginLoop();
  205.  
  206.                                         /* Tell AmigaAMP that this plugin is going down */
  207.                                         PluginMsg->PluginMask          = 0;
  208.                                         PluginMsg->PluginTask          = NULL;
  209.                                         PluginMsg->SpecRawL            = NULL;
  210.                                         PluginMsg->SpecRawR            = NULL;
  211.                                         PluginMsg->ConfigMask          = 0;
  212.                                         PluginMsg->InfoMask            = 0;
  213.                                         PluginMsg->tinfo               = NULL;
  214.                                         PluginMsg->SampleRaw           = NULL;
  215.                                         PutMsg(PluginMP, (struct Message *)PluginMsg);
  216.                                         /* Wait for confirmation before going on! */
  217.                                         WaitPort(PluginRP);
  218.                                         GetMsg(PluginRP);
  219.                                         /* Now that AmigaAMP knows that we're gone, we can quit */
  220.                                 }
  221.                                 else {
  222.                                         /* If AmigaAMP didn't accept us, tell the user about it */
  223.                                         ShowRequester("Plugin rejected by AmigaAMP!\nPerhaps there's another one running.", "Abort");
  224.                                 }
  225.  
  226.                                 /* Free all resources */
  227.                                 #ifdef __SASC
  228.  
  229.                                         PPCFreeVec(PluginMsg);
  230.                                         MyDeletePort(PluginRP);
  231.                                 #else
  232.                                         #ifndef PPC__ //SuRgEoN
  233.                                         FreeVec(PluginMsg);
  234.                                         DeletePort(PluginRP);
  235.                                         #else
  236.                                         FreeVecPPC(PluginMsg);
  237.                                         DeletePort(PluginRP);
  238.                                         #endif
  239.                                 #endif
  240.                         }
  241.                         else {
  242.                                 ShowRequester("Signal allocation failure!", "Abort");
  243.                         }
  244.                         if(PluginSignal != -1) FreeSignal(PluginSignal);
  245.                         if(ConfigSignal != -1) FreeSignal(ConfigSignal);
  246.                         if(InfoSignal   != -1) FreeSignal(InfoSignal);
  247.                 }
  248.                 else {
  249.                         ShowRequester("Could not find message port!\nAmigaAMP probably not running.", "Abort");
  250.                 }
  251.         }
  252.         else {
  253.                 ShowRequester("Plugin initialisation failed!", "Ok");
  254.         }
  255.         /* Free all user resources */
  256.         PluginExit();
  257. }
  258.  
  259. /*****************************************************************************/
  260. /* Ok, now for the individual plugin sourcecode. Everything below should be  */
  261. /* changed to your needs.                                                    */
  262. /* Just like before, we start with the global variables section              */
  263. /*****************************************************************************/
  264.  
  265. void InitWave(UBYTE WaveNum, ULONG BufNum);
  266. void CalcWave(UBYTE WaveNum, ULONG BufNum);
  267. void DrawWave(LONG *WaveX, LONG *WaveY, ULONG Width, ULONG Height, UBYTE WaveNum, ULONG BufNum);
  268.  
  269. void InitField(LONG *Zoom, ULONG Width, ULONG Height);
  270. void PrepareConstants(UBYTE FieldNum);
  271. void CalcLine(LONG *Zoom, ULONG Width, ULONG Height, UBYTE FieldNum);
  272. void MakeCMap(void);
  273. void Blur(UBYTE *PixelC, UBYTE *PixelD);
  274. void ReColor(void);
  275. void MakeTitle(void);
  276. float rnd(float max);
  277. float sgn(float val);
  278.  
  279. const char VersionString[]="\0$VER: Subspace68k 1.0 (14.03.01)";
  280. const char Line1[]="Subspace";
  281. const char Line2[]="by Thomas Wenzel";
  282.  
  283. #define PRECISION PRECISION_EXACT
  284.  
  285. struct IntuitionBase *IntuitionBase = NULL;
  286. struct GfxBase *GfxBase      = NULL;
  287. struct Library *IconBase     = NULL;
  288. struct Library *KeymapBase   = NULL;
  289. struct Library *AslBase      = NULL;
  290. struct Library *GadToolsBase = NULL;
  291. struct Library *CyberGfxBase = NULL;
  292. struct Library *P96Base = NULL;
  293. struct Screen  *PluginScreen = NULL;
  294. struct Window  *PluginWin    = NULL;
  295. struct RastPort *rp;
  296. struct ViewPort *vp;
  297.  
  298.  
  299. struct EClockVal ev1;
  300. struct EClockVal ev2;
  301.  
  302.  
  303. ULONG ModeID;
  304. ULONG WinMask;
  305.  
  306. UBYTE *PixelD;
  307. UBYTE *PixelC;
  308. ULONG *Colour;
  309.  
  310. UWORD *EmptyPointer;
  311.  
  312. char InfoLine[256];
  313.  
  314. LONG Zoom[MAXWIDTH*MAXHEIGHT];
  315. LONG Zoom2[MAXWIDTH*MAXHEIGHT];
  316. LONG WaveX[MAXWIDTH*2];
  317. LONG WaveY[MAXWIDTH*2];
  318. LONG WaveX2[MAXWIDTH*2];
  319. LONG WaveY2[MAXWIDTH*2];
  320.  
  321. ULONG MidR[4], MidG[4], MidB[4];
  322. ULONG DisplayFPS;
  323. ULONG DisplayTi;
  324. ULONG EffectLock;
  325. ULONG ShowWave;
  326. ULONG LimitFPS;
  327. #ifdef __PPC__
  328. ULONG ScreenSize = 100;
  329. #else
  330. ULONG ScreenSize = 56;
  331. #endif
  332. #ifdef PPC
  333. ULONG Width      = 320;
  334. ULONG Height     = 240;
  335. ULONG HalfHeight = 120;
  336. #else
  337. ULONG Width      = 240; //240*112    60, 256, 170
  338. ULONG Height     = 200; //120 with ScreenSize 80!
  339. ULONG HalfHeight = 100;
  340. #endif
  341. #ifndef __PPC__
  342. ULONG Woffset     = 40;// 32 for width 256
  343. #else
  344. ULONG Woffset     = 0;
  345. #endif
  346.  
  347. ULONG Cutoff     = 1;
  348. ULONG InfoCount;
  349. ULONG FrameCountLow;
  350. ULONG FrameCountHigh;
  351. ULONG FrameCountWave;
  352. ULONG FrameCountField;
  353. ULONG TimeWave;
  354. ULONG DestWaveNum;
  355. ULONG DestWaveBuffer;
  356. float WaveMorph;
  357. ULONG MidRdst[3], MidGdst[3], MidBdst[3];
  358. ULONG LineToCalc;
  359. UBYTE FieldToCalc;
  360. UBYTE WaveToCalc, WaveToCalc0, WaveToCalc1;
  361. UBYTE PrevField;
  362.  
  363. /****************************************************************************/
  364. /* This function will be called once when the plugin is started. You should */
  365. /* allocate all needed resources here. Return TRUE if all went well.        */
  366. /****************************************************************************/
  367.  
  368. BOOL PluginInit(int argc, char **argv) {
  369.         long i,xs,ys,xd,yd,ysp,ydp;
  370.         float xf,yf;
  371.         UBYTE **ttypes = 0; //VBCC
  372.         char *str;
  373.         struct DiskObject *IconObj = NULL; //VBCC
  374.         struct WBStartup  *WBStart = NULL; //VBCC
  375.         #ifdef __SASC
  376.         void *ThisTask;
  377.         #else
  378.         struct TaskPPC *ThisTask;
  379.         #endif
  380.         WORD Length;
  381.  
  382.   char *module = "CGfx_Init: ";
  383.  
  384. #ifdef __PPC__
  385.         struct TagItem ModeIDtags[] = {
  386.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 240, TAG_DONE};
  387. #else
  388. /*
  389.         struct TagItem ModeIDtags[] = {
  390.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 200, TAG_DONE};
  391. */
  392. /*
  393.         struct TagItem ModeIDtags[] = {CYBRMREQ_MinWidth, 320,  CYBRMREQ_MinHeight, 200, CYBRMREQ_MaxHeight, 240, TAG_DONE};
  394. */
  395.  
  396.   int DispID, ScrWidth, ScrHeight;
  397.   static short ColorModel[] = {PIXFMT_LUT8,-1};
  398.   struct TagItem CyberModeTags[] =
  399.   {
  400.    CYBRMREQ_MinWidth, 320, CYBRMREQ_MinHeight, 200, CYBRMREQ_MaxWidth, 320, CYBRMREQ_MaxHeight, 240, CYBRMREQ_CModelArray,(ULONG)ColorModel, TAG_DONE,0
  401.   };
  402.  
  403.  
  404. #endif
  405.         AslBase=OpenLibrary("asl.library", 0);
  406.         if(!AslBase) {
  407.                 ShowRequester("Can't open asl.library!", "Abort");
  408.                 return(FALSE);
  409.         }
  410.  
  411.         IconBase=OpenLibrary("icon.library", 0);
  412.         if(!IconBase) {
  413.                 ShowRequester("Can't open icon.library!", "Abort");
  414.                 return(FALSE);
  415.         }
  416.  
  417.         KeymapBase=OpenLibrary("keymap.library", 0);
  418.         if(!KeymapBase) {
  419.                 ShowRequester("Can't open keymap.library!", "Abort");
  420.                 return(FALSE);
  421.         }
  422.  
  423.         IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library", 0);
  424.         if(!IntuitionBase) {
  425.                 ShowRequester("Can't open intuition.library!", "Abort");
  426.                 return(FALSE);
  427.         }
  428.  
  429.         GadToolsBase=OpenLibrary("gadtools.library", 0);
  430.         if(!GadToolsBase) {
  431.                 ShowRequester("Can't open gadtools.library!", "Abort");
  432.                 return(FALSE);
  433.         }
  434.  
  435.         if(!(GfxBase= (struct GfxBase*) OpenLibrary("graphics.library", 0)))
  436.        {
  437.                 ShowRequester("Can't open graphics.library!", "Abort");
  438.                 return(FALSE);
  439.         }
  440.  
  441.         if(GfxBase->LibNode.lib_Version < 39) {
  442.                 ShowRequester("This plugin requires AmigaOS 3.0 or greater!", "Abort");
  443.                 return(FALSE);
  444.         }
  445.         if (!(CyberGfxBase = (struct Library *) OpenLibrary("cybergraphics.library", 0)))
  446.        {
  447.                 ShowRequester("This plugin requires CyberGraphX v3 or higher!", "Abort");
  448.                 return(FALSE);
  449.         }
  450.  
  451.       P96Base = (struct Library *) OpenLibrary("Picasso96API.library",0);
  452.         if(!P96Base) {
  453.                 ShowRequester("This plugin requires Picasso96", "Abort");
  454.                 return(FALSE);
  455.         }
  456.  
  457.         #ifdef __SASC
  458.                 /* Increase the priority of the 68k mirror task */
  459.                 SetTaskPri(FindTask(NULL), 15);
  460.                 /* Increase our own priority (if it only would work...) */
  461.                 PPCSetTaskAttr(PPCTASKTAG_PRIORITY, 15);
  462.         #else
  463.                 #ifdef __VBCC__
  464.         //              SetTaskPri(FindTask(NULL), 15);
  465.                 #else
  466.                 /* Increase our own priority */
  467.                 ThisTask = FindTaskPPC(NULL);
  468.                 SetNiceValue(ThisTask, -15);
  469.                 #endif
  470.         #endif
  471.  
  472.         WBStart=(struct WBStartup *)argv;
  473.  
  474. // if(argc==0) printf("IconName: %s\n", WBStart->sm_ArgList[0].wa_Name);
  475.  
  476.         if(argc==0) IconObj=GetDiskObject(WBStart->sm_ArgList[0].wa_Name);
  477.         else        IconObj=GetDiskObject(argv[0]);
  478.  
  479.         LimitFPS = 999;
  480.  
  481.         if(IconObj) {
  482.                 if(str=FindToolType(IconObj->do_ToolTypes,"MAXFPS"))
  483.                 {
  484.                         LimitFPS = atol(str);
  485.                 }
  486.  
  487.                 if(str=FindToolType(IconObj->do_ToolTypes,"RESOLUTION"))
  488.                 {
  489.                         if(stricmp(str,"high") == 0) {
  490.                                 Width      = 640;
  491.                                 Height     = 480;
  492.                                 ScreenSize = 66;
  493.                         }
  494.                         else {
  495. #ifdef __PPC__
  496.                                 Width      = 320;
  497.                                 Height     = 240;
  498.                                 ScreenSize = 100;
  499. #else
  500.                                 Width      = 240;
  501.                                 Height     = 200;
  502.                                 ScreenSize = 56;
  503. #endif
  504.  
  505.                         }
  506.                 }
  507.  
  508.                 if(str=FindToolType(IconObj->do_ToolTypes,"SCREENSIZE"))
  509.                 {
  510.                         ScreenSize = atol(str);
  511.                 }
  512.         FreeDiskObject(IconObj);
  513.         }
  514.  
  515.         if(ttypes=(UBYTE**)ArgArrayInit(argc, argv)) {
  516.                 str=(char*)ArgString(ttypes, "MAXFPS", "0");
  517.                 LimitFPS = atol(str);
  518.  
  519.                 str=(char*)ArgString(ttypes, "RESOLUTION", "low");
  520.                 if(stricmp(str,"high") == 0) {
  521.                         Width      = 640;
  522.                         Height     = 480;
  523.                         ScreenSize = 66;
  524.                         ShowWave   = 1;
  525.                 }
  526.                 else {
  527. #ifdef __PPC__
  528.                         Width      = 320;
  529.                         Height     = 240;
  530.                         ScreenSize = 100;
  531. #else
  532.                         Width      = 240; //240
  533.                         Height     = 200; //190
  534.                         ScreenSize = 56;//60
  535. #endif
  536.                         ShowWave   = 0;
  537.                 }
  538.  
  539.                 if(str=(char*)ArgString(ttypes, "SCREENSIZE", NULL)) {
  540.                         ScreenSize = atol(str);
  541.                 }
  542.  
  543.                 ArgArrayDone();
  544.         }
  545. #ifndef PPC
  546.         if(LimitFPS == 0)  LimitFPS = 999;
  547.         if(LimitFPS > 999) LimitFPS = 999;
  548. #else
  549.     LimitFPS = 10;
  550. #endif
  551.         if(ScreenSize <  25) ScreenSize =  25;
  552.         if(ScreenSize > 100) ScreenSize = 100;
  553.  
  554.         Cutoff = Height * (100-ScreenSize) / 200;
  555.         if(Cutoff <   1) Cutoff =   1;
  556.         if(Cutoff > 200) Cutoff = 200;
  557.  
  558. //        ModeIDtags[1].ti_Data = Width;
  559. //        ModeIDtags[2].ti_Data = Height;
  560. //        CyberModeTags[1].ti_Data = Width;
  561. //        CyberModeTags[2].ti_Data = Height;
  562.  
  563.         HalfHeight = Height/2;
  564.  
  565.         #if defined (__SASC) || defined (__VBCC__)
  566.                 #ifdef __PPC__
  567.                 PixelD       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  568.                 PixelC       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  569.                 Colour       = PPCAllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  570.                 EmptyPointer = PPCAllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  571.                 #else //68k
  572.                 PixelD       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  573.                 PixelC       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  574.                 Colour       = AllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  575.                 EmptyPointer = AllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  576.                 #endif
  577.         #else
  578.                 PixelD       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  579.                 PixelC       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  580.                 Colour       = AllocVecPPC(770*4,        MEMF_PUBLIC|MEMF_CLEAR, 0);
  581.                 EmptyPointer = AllocVecPPC(512,          MEMF_CHIP|MEMF_CLEAR,   0);
  582.         #endif
  583.  
  584.         OpenTimer();
  585.  
  586.         if(PixelD==NULL || PixelC==NULL) {
  587.                 ShowRequester("Out of memory for graphics buffers!", "Abort");
  588.                 return(FALSE);
  589.         }
  590.  
  591.         srand(time(NULL));
  592.  
  593.         MidR[0] = 230;
  594.         MidG[0] = 230;
  595.         MidB[0] = 230;
  596.  
  597.         MidR[1] = 86;
  598.         MidG[1] = 86;
  599.         MidB[1] = 170;
  600.  
  601.         MidR[2] = 25;
  602.         MidG[2] = 25;
  603.         MidB[2] = 100;
  604.  
  605.         MidR[3] = 0;
  606.         MidG[3] = 0;
  607.         MidB[3] = 0;
  608.  
  609.         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  610.         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  611.         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  612.  
  613.         MidRdst[1] = (UBYTE)(rand()>>25) + 96;
  614.         MidGdst[1] = (UBYTE)(rand()>>25) + 96;
  615.         MidBdst[1] = (UBYTE)(rand()>>25) + 96;
  616.  
  617.         MidRdst[2] = (UBYTE)(rand()>>25) + 64;
  618.         MidGdst[2] = (UBYTE)(rand()>>25) + 64;
  619.         MidBdst[2] = (UBYTE)(rand()>>25) + 64;
  620.  
  621.         DisplayFPS      = 0;
  622.         DisplayTi       = 1;
  623.         EffectLock      = 0;
  624.         InfoCount       = 0;
  625.         FrameCountLow   = 0;
  626.         FrameCountHigh  = 0;
  627.         FrameCountWave  = 0;
  628.         FrameCountField = 0;
  629.         TimeWave        = 0;
  630.         DestWaveNum     = 1;
  631.         DestWaveBuffer  = 1;
  632.         WaveMorph       = 0.0;
  633.         LineToCalc      = 0;
  634.         WaveToCalc      = 0;
  635.         WaveToCalc0     = 0;
  636.  
  637. FieldToCalc=16;
  638. WaveToCalc1=5;
  639.  
  640. //        FieldToCalc     = (UBYTE)(rand() % NUMFIELDS);
  641. //        WaveToCalc1     = (UBYTE)(rand() % NUMWAVES);
  642.  
  643.         PrepareConstants(FieldToCalc);
  644.  
  645.         MakeCMap();
  646.  
  647. #ifdef P96
  648. //      ModeID=CModeRequestTagList(NULL, ModeIDtags);
  649. if (!(DispID = CModeRequestTagList(NULL,CyberModeTags)))
  650. {
  651.                 ShowRequester("Could not find suitable screen mode!", "Abort");
  652.                 return(FALSE);
  653. };
  654.  
  655. //        ModeID=p96RequestModeIDTagList(ModeIDtags);
  656. #else
  657.         ModeID=BestCModeIDTagList(NULL, ModeIDtags);
  658. #endif
  659. /*
  660.         if(ModeID == INVALID_ID) {
  661.                 ShowRequester("Could not find suitable screen mode!", "Abort");
  662.                 return(FALSE);
  663.         }
  664. */        
  665. /*
  666.         PluginScreen=OpenScreenTags(NULL, SA_DisplayID, ModeID, SA_Depth, 8, SA_Width, Width, SA_Height, Height, SA_SharePens, TRUE, SA_ShowTitle, FALSE, SA_Quiet, TRUE, TAG_DONE);
  667. */
  668.   ScrWidth = GetCyberIDAttr(CYBRIDATTR_WIDTH,DispID);
  669.   ScrHeight = GetCyberIDAttr(CYBRIDATTR_HEIGHT,DispID);
  670.  
  671. PluginScreen = OpenScreenTags(NULL,
  672.                                      SA_Quiet,TRUE,
  673.                                      SA_Width,ScrWidth,
  674.                                      SA_Height,ScrHeight,
  675.                                      SA_Depth,8,
  676.                                      SA_DisplayID,DispID,
  677.                                      TAG_DONE);
  678.  
  679.   BytesPerRow = GetCyberMapAttr(PluginScreen->RastPort.BitMap,CYBRMATTR_XMOD);
  680.   GfxAddr = (BYTE *)GetCyberMapAttr(PluginScreen->RastPort.BitMap,CYBRMATTR_DISPADR);
  681.  
  682.         if(PluginScreen == NULL) {
  683.                 ShowRequester("Could not open screen!", "Abort");
  684.                 return(FALSE);
  685.         }
  686.  
  687.         rp = &PluginScreen->RastPort;
  688.         vp = &PluginScreen->ViewPort;
  689.  
  690.  
  691.         LoadRGB32(vp, Colour);
  692.  
  693.         PluginWin=OpenWindowTags(NULL, WA_CustomScreen, (ULONG)PluginScreen,
  694.                                        WA_Left,         0,
  695.                                        WA_Top,          0,
  696.                                        WA_Width,        Width,
  697.                                        WA_Height,       Height,
  698.                                        WA_SizeGadget,   FALSE,
  699.                                        WA_DragBar,      FALSE,
  700.                                        WA_DepthGadget,  FALSE,
  701.                                        WA_CloseGadget,  FALSE,
  702.                                        WA_Backdrop,     TRUE,
  703.                                        WA_Borderless,   TRUE,
  704.                                        WA_Activate,     TRUE,
  705.                                        WA_AutoAdjust,   TRUE,  // Just to be sure :-)
  706.                                        WA_IDCMP,        IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
  707.                                        TAG_DONE);
  708.         if(PluginWin == NULL) {
  709.                 ShowRequester("Could not open window!", "Abort");
  710.                 return(FALSE);
  711.         }
  712.  
  713.         SetPointer(PluginWin, EmptyPointer, 1, 1, 0, 0);
  714.         SetAPen(rp, 1);
  715.         RectFill(rp, 0, 0, (Width-1), (Height-1));
  716.         SetAPen(rp, 255);
  717.  
  718.         WinMask = 1L << PluginWin->UserPort->mp_SigBit;
  719.  
  720.         InitField(Zoom, Width, Height);
  721.         MakeTitle();
  722.  
  723.         return(TRUE);
  724. }
  725.  
  726. /******************************************************************************/
  727. /* This function will be called when the plugin is shut down. You should free */
  728. /* all previously allocated resources here.                                   */
  729. /******************************************************************************/
  730.  
  731. void PluginExit(void) {
  732.         long i;
  733.  
  734.         if(PluginWin)    CloseWindow(PluginWin);
  735.         if(PluginScreen) CloseScreen(PluginScreen);
  736.         #ifdef __SASC
  737.                 if(PixelD)       PPCFreeVec(PixelD);
  738.                 if(PixelC)       PPCFreeVec(PixelC);
  739.                 if(Colour)       PPCFreeVec(Colour);
  740.                 if(EmptyPointer) PPCFreeVec(EmptyPointer);
  741.         #else
  742.          #ifdef __PPC__ 
  743.                 if(PixelD)       FreeVecPPC(PixelD);
  744.                 if(PixelC)       FreeVecPPC(PixelC);
  745.                 if(Colour)       FreeVecPPC(Colour);
  746.                 if(EmptyPointer) FreeVecPPC(EmptyPointer);
  747.          #else
  748.                 if(PixelD)       FreeVec(PixelD);
  749.                 if(PixelC)       FreeVec(PixelC);
  750.                 if(Colour)       FreeVec(Colour);
  751.                 if(EmptyPointer) FreeVec(EmptyPointer);
  752.          #endif
  753.         #endif
  754.  
  755.         CloseTimer();
  756.         if(CyberGfxBase)  CloseLibrary(CyberGfxBase);
  757.         if(P96Base)    CloseLibrary(P96Base);
  758. //      if(GfxBase)       CloseLibrary(GfxBase);
  759.         if(AslBase)       CloseLibrary(AslBase);
  760.         if(IconBase)      CloseLibrary(IconBase);
  761.         if(KeymapBase)    CloseLibrary(KeymapBase);
  762.         if(GadToolsBase)  CloseLibrary(GadToolsBase);
  763. //      if(IntuitionBase) CloseLibrary(IntuitionBase);
  764. }
  765.  
  766. /*******************************************************************************/
  767. /* This is the main Plugin Loop. It will receive a signal matching PluginMask  */
  768. /* each time new spectral data is ready. The data is stored in two arrays,     */
  769. /* UWORD Spec[512] in structures DataL and DataR. The scale is logarithmic,    */
  770. /* 0 means below -96dB, 65535 means 0dB.                                       */
  771. /* No matter how long it takes until your plugin actually processes the data,  */
  772. /* the memory referenced by the array pointers always remains valid!           */
  773. /*                                                                             */
  774. /* Your plugin loop MUST quit when it receives SIGBREAKF_CTRL_C. If you've     */
  775. /* opened a window you should react to the close gadget as well. For full      */
  776. /* screen plugins I strongly recommend checking the ESC key.                   */
  777. /*******************************************************************************/
  778.  
  779. void PluginLoop(void) {
  780.         struct TextExtent te;
  781.         ULONG *PixelL = 0;
  782.         UBYTE *ActPixel;
  783.         ULONG Signals = 0;
  784.         LONG i,j,k;
  785.         LONG l,r;
  786.         LONG x,y;
  787.         UBYTE v;
  788.         UWORD w;
  789.         UBYTE ColorMode;
  790.  
  791.         ULONG   hi,lo,itime,eclock;
  792.         char FPStext[64];
  793.         UBYTE Vanilla;
  794.         struct InputEvent ie;
  795.         WORD    RawLen;
  796.       int ti_len,ti_center,ti_start = 0;
  797.       
  798.         //printf("entering main loop\n");
  799.         Wait(SIGBREAKF_CTRL_C | PluginMask);
  800.       
  801.  
  802.         /* Make a backup of the data pointers */
  803.         PluginRawL    = SpecRawL;
  804.         PluginRawR    = SpecRawR;
  805.         PluginSamples = SampleRaw;
  806.         WritePixelArray(PixelC, 0, 0, Width, rp, Woffset, 0, Width, Height, RECTFMT_LUT8);
  807.  
  808.         Delay(100);
  809.  
  810.         StartTimer();
  811.  
  812.         InitWave(WaveToCalc0, 0);
  813.         InitWave(WaveToCalc1, 1);
  814.  
  815.         for(;;) {
  816.                 /* Wait until there's something to do */
  817.  
  818.                 Signals=Wait(SIGBREAKF_CTRL_C | PluginMask | ConfigMask | InfoMask | WinMask | TimerMask);
  819.                 if(Signals & TimerMask) {
  820.                         WaitIO((struct IORequest *) TimerIO);
  821.                 }
  822.  
  823.                 /* Break received -> quit at once! */
  824.                 if(Signals & SIGBREAKF_CTRL_C) break;
  825.  
  826.                 /* Window close gadget hit -> quit as well! */
  827.                 if(Signals & WinMask) {
  828.                         struct IntuiMessage *imsg;
  829.                         BOOL done=0;
  830.  
  831.                         while(imsg=(struct IntuiMessage *)GetMsg(PluginWin->UserPort)) {
  832.                                 if(imsg->Class == IDCMP_RAWKEY) {
  833.                                         ie.ie_Class        = IECLASS_RAWKEY;
  834.                                         ie.ie_SubClass     = 0;
  835.                                         ie.ie_Code         = imsg->Code;
  836.                                         ie.ie_Qualifier    = 0;
  837.                                         ie.ie_EventAddress = imsg->IAddress;
  838.                                         RawLen = MapRawKey(&ie, &Vanilla, 1, 0);
  839.  
  840.                                         switch(imsg->Code) {
  841.                                                 case 0x45: done=1; break;
  842.                                         }
  843.  
  844.                                         if(RawLen==1) {
  845.                                                 switch(Vanilla) {
  846.                                                         case 'f': DisplayFPS = 1-DisplayFPS; break;
  847.                                                         case 'w': ShowWave   = 1-ShowWave;   break;
  848.                                                         case 'i': InfoCount  = 0;            break;
  849.                               case 't': if(!DisplayTi) DisplayTi = 1;else DisplayTi = 0;        break;
  850.                               case 'l': if(!EffectLock) EffectLock = 1;else EffectLock = 0;        break;
  851.  
  852. //                                              case '+': Cutoff--;                  break;
  853. //                                              case '-': Cutoff++;                  break;
  854.                                                 }
  855.                                                 if(Cutoff < 1) Cutoff =   1;
  856.                                                 if(Cutoff > HalfHeight-10) Cutoff = HalfHeight-10;
  857.                                                 for(i=0; i<Width*Cutoff; i++) {
  858.                                                         PixelC[i]=PixelD[i]=0;
  859.                                                 }
  860.                                                 for(i=Width*(Height-Cutoff); i<Width*Height; i++) {
  861.                                                         PixelC[i]=PixelD[i]=0;
  862.                                                 }
  863.                                         }
  864.                                 }
  865.                                 ReplyMsg((struct Message *)imsg);
  866.                         }
  867.                         if(done) break;
  868.                 }
  869.  
  870.                 if(Signals & TimerMask) {
  871.                         StartTimer();
  872. //printf("timer started\n");
  873.       Blur(PixelC, PixelD);
  874.  
  875.                         FrameCountLow++;
  876.                         if(FrameCountLow > 4) {
  877.                                 FrameCountLow = 0;
  878.                                 eclock=ReadEClock(&ev2);
  879.                                 hi = ev2.ev_hi - ev1.ev_hi;
  880.                                 lo = ev2.ev_lo - ev1.ev_lo;
  881.                                 itime = hi*eclock+lo;
  882.  
  883.                                 if(itime==0) itime=1;
  884.  
  885.                                 ev1.ev_hi = ev2.ev_hi;
  886.                                 ev1.ev_lo = ev2.ev_lo;
  887.                                 ReColor();
  888.                         }
  889.  
  890.                         FrameCountHigh++;
  891.                 if(FrameCountHigh > 600) {
  892.                                 FrameCountHigh = 0;
  893. #ifndef __VBCC__
  894.                                 ColorMode = (UBYTE)(rand()>>24) % 10;
  895.  
  896. #else
  897. /*
  898. if(ColorMode==0)
  899. {
  900.         MidR[0] = 255;
  901.         MidG[0] = 220;
  902.         MidB[0] = 200;
  903.  
  904.         MidR[1] = 170;
  905.         MidG[1] = 96;
  906.         MidB[1] = 170;
  907.  
  908.         MidR[2] = 10;
  909.         MidG[2] = 100;
  910.         MidB[2] = 52;
  911.  
  912. ColorMode=1;
  913. }
  914. */
  915. /*
  916. if(ColorMode==0)
  917. {
  918.         MidR[0] = 255;
  919.         MidG[0] = 200;
  920.         MidB[0] = 255;
  921.  
  922.         MidR[1] = 96;
  923.         MidG[1] = 76;
  924.         MidB[1] = 178;
  925.  
  926.         MidR[2] = 100;
  927.         MidG[2] = 55;
  928.         MidB[2] = 65;
  929.  
  930. ColorMode=1;
  931. }
  932. */
  933.  
  934. if(ColorMode == 0)
  935. {
  936. //blue
  937.         MidR[0] = 230;
  938.         MidG[0] = 230;
  939.         MidB[0] = 230;
  940.  
  941.         MidR[1] = 86;
  942.         MidG[1] = 86;
  943.         MidB[1] = 170;
  944.  
  945.         MidR[2] = 25;
  946.         MidG[2] = 25;
  947.         MidB[2] = 100;
  948.  
  949. ColorMode = 1;
  950. }
  951. else
  952. {
  953. //fire
  954.         MidR[0] = 255;
  955.         MidG[0] = 255;
  956.         MidB[0] = 100;
  957.  
  958.         MidR[1] = 200;
  959.         MidG[1] = 120;
  960.         MidB[1] = 10;
  961.  
  962.         MidR[2] = 100;
  963.         MidG[2] = 25;
  964.         MidB[2] = 25;
  965.  
  966.         MidR[3] = 0;
  967.         MidG[3] = 0;
  968.         MidB[3] = 0;
  969.  
  970. ColorMode = 0;
  971. }
  972.  
  973. #endif
  974.                         //printf("ColorMode: %d\n", ColorMode);
  975. #ifndef __VBCC__
  976.                                 switch(ColorMode) {
  977.                                         case 0:
  978.                                         case 1:
  979.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  980.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  981.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  982.  
  983.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  984.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  985.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  986.  
  987.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  988.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  989.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  990.                                         break;
  991.  
  992.                                         case 2:
  993.                                                 MidRdst[0] = (UBYTE)(rand()>>24) + 0;
  994.                                                 MidGdst[0] = (UBYTE)(rand()>>24) + 0;
  995.                                                 MidBdst[0] = (UBYTE)(rand()>>24) + 0;
  996.  
  997.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  998.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  999.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  1000.  
  1001.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  1002.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  1003.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  1004.                                         break;
  1005.  
  1006.                                         case 3:
  1007.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 0;
  1008.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 0;
  1009.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 0;
  1010.  
  1011.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  1012.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  1013.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  1014.  
  1015.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  1016.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  1017.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  1018.                                         break;
  1019.  
  1020.                                         default:
  1021.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  1022.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  1023.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  1024.  
  1025.                                                 MidRdst[1] = (UBYTE)(rand()>>25) + 64;
  1026.                                                 MidGdst[1] = (UBYTE)(rand()>>25) + 64;
  1027.                                                 MidBdst[1] = (UBYTE)(rand()>>25) + 64;
  1028.  
  1029.                                                 MidRdst[2] = (UBYTE)(rand()>>25) + 32;
  1030.                                                 MidGdst[2] = (UBYTE)(rand()>>25) + 32;
  1031.                                                 MidBdst[2] = (UBYTE)(rand()>>25) + 32;
  1032.                                         break;
  1033.                                 }
  1034. #endif
  1035.                         }
  1036.  
  1037.                         CalcLine(Zoom2, Width, Height, FieldToCalc);
  1038.                         LineToCalc++;
  1039.                         if(LineToCalc > Height-1) LineToCalc = Height-1;
  1040.                         if(!EffectLock)FrameCountField++;
  1041.                         
  1042.                         if(FrameCountField > 500) {
  1043.  
  1044.                         //printf("FCF 500\n");
  1045.                                 FrameCountField=0;
  1046.  
  1047.                                 LineToCalc = 1;
  1048.                                 PrevField = FieldToCalc;
  1049.  
  1050. #ifdef __VBCC__
  1051.                                 do {
  1052.                         FieldToCalc=(UBYTE)(rand() % NUMFIELDS);
  1053.                                 } while (FieldToCalc == PrevField);
  1054.  
  1055. /*                              if(FieldToCalc == 0)
  1056.                                 FieldToCalc = 1;
  1057.                                 else if(FieldToCalc == 1)
  1058.                                 FieldToCalc = 2;
  1059.                                 else if(FieldToCalc == 2)
  1060.                                 FieldToCalc = 3;
  1061.                                 else if(FieldToCalc == 3)
  1062.                                 FieldToCalc = 4;
  1063.                                 else if(FieldToCalc == 4)
  1064.                                 FieldToCalc = 6;
  1065.                                 else if(FieldToCalc == 6)
  1066.                                 FieldToCalc = 7;
  1067.                                 else if(FieldToCalc == 7)
  1068.                                 FieldToCalc = 9;
  1069.                                 else if(FieldToCalc == 9)
  1070.                                 FieldToCalc = 10;
  1071.                                 else if(FieldToCalc == 10)
  1072.                                 FieldToCalc = 13;
  1073.                                 else if(FieldToCalc == 13)
  1074.                                 FieldToCalc = 14;
  1075.                                 else if(FieldToCalc == 14)
  1076.                                 FieldToCalc = 15;
  1077.                                 else if(FieldToCalc == 15)
  1078.                                 FieldToCalc = 16;
  1079.                                 else if(FieldToCalc == 16)
  1080.                                 FieldToCalc = 18;
  1081.                                 else
  1082.                                 FieldToCalc = 0;
  1083. */
  1084. #endif
  1085.  
  1086. #ifndef __VBCC__
  1087.                                 do {
  1088.                         FieldToCalc=(UBYTE)(rand()>>24) % NUMFIELDS;
  1089.                                 } while (FieldToCalc == PrevField);
  1090. #endif
  1091.  
  1092.                                 for(j=0; j<Width*Height; j++)
  1093.                                 {
  1094.                                         Zoom[j]=Zoom2[j];
  1095.                                 }
  1096.                                 //printf("preparing field %d\n", FieldToCalc);
  1097.                                 PrepareConstants(FieldToCalc);
  1098.  
  1099.                         }
  1100.  
  1101.                         for(i=Width*Cutoff; i<Width*(Height-Cutoff); i++) {
  1102.                                 PixelC[i]=PixelD[Zoom[i]];
  1103.                         }
  1104.  
  1105.  
  1106.                         /* Make a backup of the data pointers */
  1107.                         PluginRawL    = SpecRawL;
  1108.                         PluginRawR    = SpecRawR;
  1109.                         PluginSamples = SampleRaw;
  1110.  
  1111.                         InfoCount++;
  1112.                         if(InfoCount < 75) MakeTitle();
  1113.                         else InfoCount=75;
  1114.  
  1115.                         //TimeWave++;
  1116. /*
  1117. surgeon:frametiming ++ for 20fps; +2 for 10fps; +4 for 5fps
  1118. */
  1119.             TimeWave+=2; //framerate adjust
  1120.  
  1121.                         if(!EffectLock)FrameCountWave++;
  1122.                         CalcWave(WaveToCalc0, 0);
  1123.                         DrawWave(WaveX,  WaveY,  Width, Height, WaveToCalc0, 0);
  1124.                         CalcWave(WaveToCalc1, 1);
  1125.                         DrawWave(WaveX2, WaveY2, Width, Height, WaveToCalc1, 1);
  1126.                         if(FrameCountWave > 200) {
  1127.  
  1128.                                 if(DestWaveBuffer == 1) WaveMorph += 0.015; //was 0.005
  1129.                                 else                    WaveMorph -= 0.015; //was 0.005
  1130.                         }
  1131.                         if (WaveMorph > 1.0) WaveMorph = 1.0;
  1132.                         if (WaveMorph < 0.0) WaveMorph = 0.0;
  1133.  
  1134.                         if(FrameCountWave > 400) {
  1135.                         //printf("FCW 400\n");
  1136.                         FrameCountWave = 0;
  1137.                         DestWaveBuffer = 1 - DestWaveBuffer;
  1138. #ifdef __VBCC__
  1139.                                 do {
  1140.                                         WaveToCalc = (UBYTE)(rand() % NUMWAVES);
  1141.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1 || WaveToCalc == 10 || WaveToCalc == 8 || WaveToCalc == 6);
  1142.  
  1143.                                 if(DestWaveBuffer) {
  1144.                                         WaveToCalc1 = WaveToCalc;
  1145.                                         InitWave(WaveToCalc1, 1);
  1146.                                 }
  1147.                                 else {
  1148.                                         WaveToCalc0 = WaveToCalc;
  1149.                                         InitWave(WaveToCalc0, 0);
  1150.                                 }
  1151.  
  1152. /*
  1153. if (WaveToCalc1 == 1)
  1154. WaveToCalc1 = 5;
  1155. else if (WaveToCalc1 == 2)
  1156. WaveToCalc1 = 7;
  1157. else if (WaveToCalc1 == 3)
  1158. WaveToCalc1 = 11;
  1159. else if (WaveToCalc1 == 4)
  1160. WaveToCalc1 = 1;
  1161. else if (WaveToCalc1 == 5)
  1162. WaveToCalc1 = 2;
  1163. else if (WaveToCalc1 == 7)
  1164. WaveToCalc1 = 3;
  1165. else
  1166. WaveToCalc1 = 4;
  1167.  
  1168. WaveToCalc0 = 0;
  1169.  
  1170.         InitWave(WaveToCalc1, 1);
  1171.         //printf("initializing wave %d\n",WaveToCalc1);
  1172.         InitWave(WaveToCalc0, 0);
  1173. */
  1174. #endif
  1175.  
  1176. #ifndef __VBCC__
  1177.                                 do {
  1178.                                         WaveToCalc = (UBYTE)(rand()>>24) % NUMWAVES;
  1179.                                         WaveToCalc = NUMWAVES-1;
  1180.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1);
  1181.  
  1182.                                 if(DestWaveBuffer) {
  1183.                                         WaveToCalc1 = WaveToCalc;
  1184.                                         InitWave(WaveToCalc1, 1);
  1185.                                 }
  1186.                                 else {
  1187.                                         WaveToCalc0 = WaveToCalc;
  1188.                                         InitWave(WaveToCalc0, 0);
  1189.                                 }
  1190. #endif
  1191.                         }
  1192.  
  1193.                         for(i=0; i<Width*2; i++) {
  1194.                                 float xf,yf;
  1195.                                 ULONG x,y;
  1196.                                 xf = (float)WaveX[i]*(1.0-WaveMorph) + (float)WaveX2[i]*(WaveMorph);
  1197.                                 yf = (float)WaveY[i]*(1.0-WaveMorph) + (float)WaveY2[i]*(WaveMorph);
  1198.                                 x  = (ULONG)xf + Width/2;
  1199.                                 y  = (ULONG)yf + Height/2;
  1200.                                 if(x < Width-1) {
  1201.                                         if(y < Height-1) {
  1202.                                                 if(x > 0) {
  1203.                                                         if(y > 0) {
  1204.                                                                 ActPixel = PixelC + y * Width + x;
  1205.                                                                 *ActPixel=255;
  1206.                                                         }
  1207.                                                 }
  1208.                                         }
  1209.                                 }
  1210.                         }
  1211.  
  1212.                         SetAPen(rp, 0);
  1213. /*                      if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1214.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1215.                         RectFill(rp, 0, 0, Width, Cutoff);
  1216.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1217. */
  1218.                         if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1219.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1220.                         RectFill(rp, 0, 0, Width, Cutoff);
  1221.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1222.  
  1223.  
  1224.  
  1225.  
  1226.                         if(DisplayFPS)
  1227.                         {
  1228.                                 Move(rp, 0, 15);
  1229.                                 SetABPenDrMd(rp, 255, 0, JAM2);
  1230.                                 sprintf(FPStext, "%3ld fps       ", 5*eclock/itime);
  1231.                                 Text(rp, FPStext, 7);
  1232.                         }
  1233.  
  1234. /* New track info has arrived! */
  1235.         if(Signals & InfoMask)
  1236.         {
  1237.         if(tinfo)
  1238.             {
  1239. /* process contents of tinfo here */
  1240. /* see "TrackInfo.h" for details! */
  1241. /* Example: Display the track info text */
  1242.             if(tinfo->TrackInfoText)
  1243.             sprintf(InfoLine, "%s", tinfo->TrackInfoText);
  1244.             }
  1245.         }
  1246.  
  1247.         SetABPenDrMd(rp, 0, 0, JAM2);
  1248.         RectFill(rp, 0, 160, 320, 40);
  1249.  
  1250.         if(DisplayTi && InfoLine)
  1251.             {
  1252.             ti_len = strlen(InfoLine);
  1253.             Move(rp, Woffset, 170);
  1254.             SetABPenDrMd(rp, 255, 0, JAM2);
  1255.             Text(rp, InfoLine, ti_len);
  1256.             }
  1257.                 }
  1258.         }
  1259. }
  1260.  
  1261.  
  1262.  
  1263.  
  1264. void Blur(UBYTE *PixelC, UBYTE *PixelD) {
  1265.   UBYTE *ActPixel;
  1266.   UBYTE *DstPixel;
  1267.   UBYTE *AbovePixel, *BelowPixel;
  1268.   UBYTE Left, Act, Right;
  1269.   WORD w;
  1270.   ULONG i;
  1271.  
  1272.         PixelC += Width*Cutoff;
  1273.         PixelD += Width*Cutoff;
  1274.  
  1275.   ActPixel   = PixelC+Width+1;
  1276.   AbovePixel = ActPixel-Width;
  1277.   BelowPixel = ActPixel+Width;
  1278.   DstPixel   = PixelD+Width+1;
  1279.  
  1280.   Left  = 0;
  1281.   Act   = 0;
  1282.   Right = 0;
  1283.  
  1284.         for(i=Width*(Cutoff+1); i<(Width*(Height-Cutoff-2)-2); i++) {
  1285.     Right = *(ActPixel+1);
  1286.  
  1287.     w = (Right + Act + Left + *AbovePixel + *BelowPixel) * 3 / 16;
  1288.                 if(w<0) w=0;
  1289.     *DstPixel++ = w;
  1290.  
  1291.     ActPixel++;
  1292.     AbovePixel++;
  1293.     BelowPixel++;
  1294.  
  1295.     Left = Act;
  1296.     Act = Right;
  1297.   }
  1298. }
  1299.  
  1300. void ShowRequester(char *Text, char *Button) {
  1301.         struct EasyStruct Req;
  1302.         Req.es_StructSize   = sizeof(struct EasyStruct);
  1303.         Req.es_Flags        = 0;
  1304.   Req.es_Title        = "AmigaAMP Plugin";
  1305.   Req.es_TextFormat   = (UBYTE*)Text;
  1306.   Req.es_GadgetFormat = (UBYTE*)Button;
  1307.         EasyRequestArgs(NULL, &Req, NULL, NULL);
  1308. }
  1309.  
  1310. BOOL OpenTimer(void) {
  1311.         struct EClockVal ev = {0,0};
  1312.  
  1313.         if(TimerMP=(struct MsgPort*)CreatePort(0,0)) {
  1314.                 if(TimerIO=(struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))) {
  1315.                         TimerError=OpenDevice("timer.device", UNIT_ECLOCK, (struct IORequest *)TimerIO, 0);
  1316.                         if(TimerError==0) {
  1317.  
  1318.                                 TimerBase = (struct Library*) &TimerIO->tr_node.io_Device->dd_Library;
  1319.                                 EFreq=ReadEClock(&ev);
  1320.  
  1321.                                 TimerMask = 1L << TimerMP->mp_SigBit;
  1322.  
  1323.                                 return(TRUE);
  1324.                         }
  1325.                 }
  1326.         }
  1327.         return(FALSE);
  1328. }
  1329.  
  1330. void CloseTimer(void) {
  1331.         if(!TimerError)   CloseDevice((struct IORequest *)TimerIO);
  1332.         if(TimerIO)       DeleteIORequest(TimerIO);
  1333.         if(TimerMP)       DeletePort(TimerMP);
  1334. }
  1335.  
  1336. void StartTimer(void) {
  1337.         TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  1338.         TimerIO->tr_node.io_Flags   = 0;
  1339.         TimerIO->tr_time.tv_secs    = 0;
  1340.         TimerIO->tr_time.tv_micro   = EFreq/LimitFPS;
  1341.         SendIO((struct IORequest *)TimerIO);
  1342. }
  1343.  
  1344. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri) {
  1345.         int sigBit;
  1346.         struct MsgPort *mp;
  1347.  
  1348.         if((sigBit = AllocSignal(-1L)) == -1)   return(NULL);
  1349.  
  1350.         mp = (struct MsgPort*) AllocVec(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
  1351.  
  1352.         if(!mp) {
  1353.                 FreeSignal(sigBit);
  1354.                 return(NULL);
  1355.         }
  1356.  
  1357.         mp->mp_Node.ln_Name = name;
  1358.         mp->mp_Node.ln_Pri  = pri;
  1359.         mp->mp_Node.ln_Type = NT_MSGPORT;
  1360.         mp->mp_Flags        = PA_SIGNAL;
  1361.         mp->mp_SigBit       = sigBit;
  1362.         mp->mp_SigTask      = FindTask(NULL);
  1363.         if(name) AddPort(mp);
  1364.         #if defined (__SASC) || defined (__VBCC__)
  1365.                 else NewList(&(mp->mp_MsgList));
  1366.         #else
  1367.                 else NewListPPC(&(mp->mp_MsgList));
  1368.         #endif
  1369.  
  1370.         return(mp);
  1371. }
  1372.  
  1373. void MyDeletePort(struct MsgPort *mp) {
  1374.         if(mp->mp_Node.ln_Name) RemPort(mp);
  1375.         mp->mp_SigTask         = (struct Task *) -1;
  1376.         mp->mp_MsgList.lh_Head = (struct Node *) -1;
  1377.         FreeSignal(mp->mp_SigBit);
  1378.         FreeVec(mp); mp=NULL;
  1379. }
  1380.  
  1381. void InitField(LONG *Zoom, ULONG Width, ULONG Height) {
  1382.         LONG i,xs,ys,xd,yd;
  1383.  
  1384.         float scale,greater;
  1385.         float xsf,ysf,xdf,ydf;
  1386.         float rsf,tsf,rdf,tdf;
  1387.         float wf,hf;
  1388.  
  1389.         wf=(float)Width;
  1390.         hf=(float)Height;
  1391.  
  1392.         greater=1.0;
  1393.         if(wf > greater) greater = wf;
  1394.         if(hf > greater) greater = hf;
  1395.  
  1396.         scale = 1.0 / (greater/2.0);
  1397.  
  1398.         for(yd=0; yd<(Height); yd++) {
  1399.                 for(xd=0; xd<(Width); xd++) {
  1400.                         xdf = (xd - wf/2.0) * scale;
  1401.                         ydf = (yd - hf/2.0) * scale;
  1402.  
  1403.                         xsf = xdf - xdf * 0.075;
  1404.                         ysf = ydf - ydf * 0.075;
  1405.  
  1406.                         xs = xsf/scale + wf/2.0;
  1407.                         ys = ysf/scale + hf/2.0;
  1408.  
  1409.                         if(xs < Width/2)  xs++;
  1410.                         if(ys < Height/2) ys++;
  1411.  
  1412.                         if(xs < 0)      xs = 0;
  1413.                         if(xs > Width)  xs = Width;
  1414.                         if(ys < 0)      ys = 0;
  1415.                         if(ys > Height) ys = Height;
  1416.  
  1417.                         Zoom[Width * yd + xd] = Width * ys + xs;
  1418.                 }
  1419.         }
  1420. }
  1421.  
  1422.  
  1423. void MakeCMap(void) {
  1424.         int j,i,c;
  1425.         float r,g,b;
  1426.         float rs,gs,bs;
  1427.  
  1428.         r=255; g=255; b=255;
  1429.  
  1430.         c=255;
  1431.  
  1432.         Colour[0]=256L<<16+0;
  1433.  
  1434.         for(j=0; j<4; j++) {
  1435.                 rs = (r - (float)MidR[j]) / 64.0;
  1436.                 gs = (g - (float)MidG[j]) / 64.0;
  1437.                 bs = (b - (float)MidB[j]) / 64.0;
  1438.                 for(i=0; i<64; i++) {
  1439.                         Colour[1+3*c+0] = (ULONG)r << 24;
  1440.                         Colour[1+3*c+1] = (ULONG)g << 24;
  1441.                         Colour[1+3*c+2] = (ULONG)b << 24;
  1442.                         r -= rs;
  1443.                         g -= gs;
  1444.                         b -= bs;
  1445.                         c--;
  1446.                 }
  1447.         }
  1448.  
  1449. }
  1450.  
  1451. void MakeTitle(void) {
  1452.         long x,y,i,p,s,v,xs,ys;
  1453.         UWORD Blt1[27] = {
  1454.                 0x7008,0x0000,0x0000,0x8808,0x0000,0x0000,0x822B,0x1963,
  1455.                 0x8E38,0x722C,0xA590,0x5144,0x0A28,0x9913,0xD07C,0x8A28,
  1456.                 0x8514,0x5040,0x8A68,0xA594,0xD144,0x71AF,0x1963,0x4E38,
  1457.                 0x0000,0x0100,0x0000
  1458.         }; // W=46, H=9
  1459.         UWORD Blt2[54] = {
  1460.                 0x8001,0xF400,0x0000,0x0101,0x0000,0x0080,0x8000,0x4400,
  1461.                 0x0000,0x0111,0x0000,0x0080,0xB220,0x458E,0x7638,0xC111,
  1462.                 0x3967,0x9C80,0xCA20,0x4651,0x4905,0x2092,0x4590,0xA280,
  1463.                 0x8940,0x4451,0x493C,0xC0AA,0x7D11,0x3E80,0x8940,0x4451,
  1464.                 0x4944,0x20AA,0x4112,0x2080,0x8880,0x4451,0x494D,0x2044,
  1465.                 0x4514,0x2280,0xF080,0x444E,0x4934,0xC044,0x3917,0x9C80,
  1466.                 0x0100,0x0000,0x0000,0x0000,0x0000,0x0000
  1467.         }; // W=89, H=9
  1468.  
  1469.         xs = (Width-46)/2;
  1470.         ys = Height/2-30-9;
  1471.         s=0;
  1472.         for(y=0; y<9; y++) {
  1473.                 x=0;
  1474.                 for(i=0; i<3; i++) {
  1475.                         for(p=0; p<16; p++) {
  1476.                                 x++;
  1477.                                 v = Blt1[s] & (1<<(15-p));
  1478.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1479.                         }
  1480.                         s++;
  1481.                 }
  1482.         }
  1483.         xs = (Width-89)/2;
  1484.         ys = Height/2+30;
  1485.         s=0;
  1486.         for(y=0; y<9; y++) {
  1487.                 x=0;
  1488.                 for(i=0; i<6; i++) {
  1489.                         for(p=0; p<16; p++) {
  1490.                                 x++;
  1491.                                 v = Blt2[s] & (1<<(15-p));
  1492.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1493.                         }
  1494.                         s++;
  1495.                 }
  1496.         }
  1497. }
  1498.  
  1499.  
  1500. void ReColor(void) {
  1501. #ifndef __VBCC__
  1502.  
  1503.         int i;
  1504.         for(i=0; i<3; i++) {
  1505.                 if(MidR[i] > MidRdst[i]) MidR[i] --;
  1506.                 if(MidG[i] > MidGdst[i]) MidG[i] --;
  1507.                 if(MidB[i] > MidBdst[i]) MidB[i] --;
  1508.                 if(MidR[i] < MidRdst[i]) MidR[i] ++;
  1509.                 if(MidG[i] < MidGdst[i]) MidG[i] ++;
  1510.                 if(MidB[i] < MidBdst[i]) MidB[i] ++;
  1511.  
  1512.         }
  1513. #endif
  1514.         MakeCMap();
  1515.         LoadRGB32(&PluginScreen->ViewPort, Colour);
  1516. }
  1517.  
  1518. float rnd(float max) {
  1519.         ULONG r;
  1520.         ULONG m;
  1521.  
  1522.         m = (ULONG)(max * 10000.0);
  1523. #ifndef __VBCC__
  1524.         r=(rand()>>8) % m;
  1525. #else
  1526.         r=(rand() % m);
  1527. #endif
  1528.         return (float)r/10000.0;
  1529. }
  1530.  
  1531. float sgn(float val) {
  1532.         if(val > 0.0) return  1.0;
  1533.         if(val < 0.0) return -1.0;
  1534.         return 0.0;
  1535. }
  1536.  
  1537. float trnc(float value) {
  1538.         return ceil(value);
  1539. }
  1540.  
  1541. #ifdef __SASC
  1542. void SetPriority(void) {
  1543.         struct TagItem MyTags[2];
  1544.         if(PPCLibBase=OpenLibrary("ppc.library",0)) {
  1545.                 MyTags[0].ti_Tag  = PPCTASKTAG_PRIORITY;
  1546.                 MyTags[0].ti_Data = 15;
  1547.                 MyTags[1].ti_Tag         = TAG_END;
  1548.                 CloseLibrary(PPCLibBase);
  1549.         }
  1550. }
  1551. #endif
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.